<?php
namespace app\shouyin\model;

use think\Model;
use app\shouyin\model\Subscribe;
use app\product\model\Project as ProjectModel;
use think\Db;
class SubscribeProject extends Model
{
    // 定义时间戳字段名
    protected $createTime = 'createtime';
    protected $updateTime = 'updatetime';
    // 自动写入时间戳
    protected $autoWriteTimestamp = true;
    public function setTechnicianIdsAttr($value,$data)
    {
        return implode(',',$data['technician_ids']);
    }

    public function getTechnicianIdsAttr($value)
    {
        return explode(',',$value);
    }
    public function getTechnicianTextAttr($value)
    {
        $admins = Db::name('system_user')->where('id','in',$value)->column('nick');
        return $admins;
    }
    public function getAdviserTextAttr($value)
    {
        $admins = Db::name('system_user')->where('id',$value)->column('nick');
        return $admins;
    }
    public function getSettlementTextAttr($value)
    {
        // 1=现金消费，2=储值卡，3=赠送，4=疗程卡
        $settlement = [
            '1' => '现金消费',
            '2' => '储值卡',
            '3' => '赠送',
            '4' => '疗程卡',
        ];
        return $settlement[$value];
    }
    public function BlogSubscribe()
    {
        return $this->belongsTo('Subscribe','sub_id','id');
    }
    public function getProNameAttr($value,$data)
    {
        $project = ProjectModel::get($value);
        return $project['name'];
    }
    // public function hasShop()
    // {
    //     return $this->hasOne('app\shop\model\Shop', 'id', 'shop_id');
    // }
    // public function hasUser()
    // {
    //     return $this->hasOne('app\user\model\User', 'id', 'user_id');
    // }
    // public function hasRoom()
    // {
    //     return $this->hasOne('app\shop\model\Room', 'id', 'room_id');
    // }
}
